package cx3k.dataaccess.search;

import java.util.Collection;
import java.util.LinkedList;

public abstract class SearchNode {

	private String className;
	private String nickName;
	
	private SearchNode parent;
	private Collection<SearchNode> children;
	
	public SearchNode(Class<?> className){
		String name = className.getName();
		
		String[] split = name.split("\\.");
		init(split[split.length-1]);
	}
	
	public SearchNode(String className){
		init(className);
	}
	
	private void init(String className){
		setClassName(className);
		setNickName(className.toLowerCase());
		setChildren(new LinkedList<SearchNode>());
	}
	
	private void setChildren(Collection<SearchNode> children){
		this.children = children;
	}
	
	protected Collection<SearchNode> getChildren(){
		return children;
	}
	
	public void addChild(SearchNode child){
//		child.setParent(this);
		getChildren().add(child);
	}
	
	public void removeChild(SearchNode child){
		child.setParent(null);
		getChildren().remove(child);
	}
	
	public void setParent(SearchNode parent){
		this.parent = parent;
	}
	
	public SearchNode getParent(){
		return parent;
	}
	
	
	
	protected String getClassName(){
		return className;
	}
	
	protected String getNickName(){
		return nickName;
	}
	
	public abstract String getDefaultQueryStr();
	
	private void setClassName(String className){
		this.className = className;
	}
	
	private void setNickName(String nickName){
		this.nickName = nickName;
	}
}
